package com.google.antranking.activity;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import com.google.antranking.AntRankingActivity;
import com.google.antranking.R;
import com.google.antranking.utils.AtConfiguration;
import com.google.antranking.utils.AtConstant;
import com.google.antranking.utils.HttpRequestUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class RankingActivity extends Activity implements android.view.View.OnClickListener{
	private TextView score;
	private String user;
	private Button btOk;
	
	private InputStream scoreStream;
	private String scoreTexte;
	public void onCreate(Bundle test){
		super.onCreate(test);
		setContentView(R.layout.layout_ranking_xp);
		this.score = (TextView) findViewById(R.id.layout_ranking_score);
		
		this.user = AtConfiguration.getStringValue(this, AtConstant.PREF_USERNAME, null);	
		((Button) this.findViewById(R.id.layout_ranking_btOk)).setOnClickListener(this);

		HttpRequestUtils rq = new HttpRequestUtils();
		CharSequence[] params = {"user=adnerst"};
		try {
			scoreStream = rq.sendGetRequest("http://localhost:8090/manager/getClassement", params);
			scoreTexte = HttpRequestUtils.convertStreamToString(scoreStream);
			System.out.println(scoreTexte);
			this.score.setText(scoreTexte);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void onClick(View v) {
		final Button button = (Button) v;
		if (button.getText().equals("OK")){
			final Intent back = new Intent(this, AntRankingActivity.class);
			startActivity(back);
		}
	}
}
